setTimeout("document.getElementById('welcome').style.transform='rotate(-10deg)'", 500);
setInterval("swing()", 3000);

function swing() {
	document.getElementById('welcome').style.transform = 'rotate(10deg)';
	setTimeout("document.getElementById('welcome').style.transform='rotate(-10deg)'", 1500);
}

document.getElementById("welcome").onclick = function(e) {
	var welcome = document.getElementById("welcome");
	var fome1 = document.getElementById("login");
	var fome2 = document.getElementById("registe");
	var flag = document.getElementById("loginForm").flag;
	//        console.log(flag);

	if(flag.value == 0) {
		fome1.style.left = "45%";

		welcome.style.top = "10%";
		welcome.style.transform = "rotate(355deg) scale(0.75)";

		flag.value = 1;
	} else {
		fome1.style.left = "150%";
		fome2.style.left = "-50%";
		welcome.style.top = "40%";
		welcome.style.transform = "rotate(-355deg) scale(1.5)";
		flag.value = 0;
	}
}

document.getElementById("moonPic").onclick = function(e) {
	var flag = document.getElementById("adjustForm").flag;
	if(flag.value == 0) {
		document.getElementById("adjustForm").style.visibility = 'visible';
		document.getElementById("adjustForm").style.width = '300px';
		//                document.getElementById("adjustForm").style.top=e.clientTop;
		//                document.getElementById("adjustForm").style.left+e.clientLeft;
		flag.value = 1;
	} else if(flag.value == 1) {
		document.getElementById("adjustForm").style.width = '80px';
		flag.value = 2;
	} else if(flag.value == 2) {
		document.getElementById("adjustForm").style.visibility = 'hidden';

		//            document.getElementById("adjustForm").style.top='-500px';
		//            document.getElementById("adjustForm").style.left='-500px';
		flag.value = 0;
	}

}


function goRegiste() {
	var fome1 = document.getElementById("login");
	var fome2 = document.getElementById("registe");

	fome2.style.left = "45%";
	fome1.style.left = "-50%";
}

function goLogin() {
	var fome1 = document.getElementById("login");
	var fome2 = document.getElementById("registe");

	fome2.style.left = "150%";
	fome1.style.left = "45%";
}

function createXMLHttpRequest() { //万能模板

	var XMLHttpReq;

	if(window.XMLHttpRequest) { // 是Mozilla浏览器

		XMLHttpReq = new XMLHttpRequest();
	} else if(window.ActiveXObject()) { // IE浏览器
		try {
			XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP"); //因为ie也会出现不兼容所以抛异常
		} catch(e) {
			XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); //微软的，记住就好
		}
	}
	return XMLHttpReq;
}

function tryLogin() {

	var account = document.getElementById('loginForm').account.value;
	var password = document.getElementById('loginForm').password.value;
	if(!account) {
		document.getElementById("checkFlag").innerHTML = "请输入账户！";
		return 0;
	} else if(!password) {
		document.getElementById("checkFlag").innerHTML = "请输入账户密码！";
		return 0;
	};

		var xmlReq = createXMLHttpRequest();

		xmlReq.open("GET", "../Login?account=" + account + "&password=" + password, true);

		xmlReq.send(null);
		console.log(xmlReq);

		xmlReq.onreadystatechange = function() {
			if(xmlReq.readyState == 4) { //判断对象状态是否完成
				if(xmlReq.status == 200) { //信息已经成功返回
					var xmltext = xmlReq.responseText; //得到AjaxServlet往外输出的数据
					if(xmltext == 1) {
						alert("登录成功!");
						window.location.href = "dragin.html";
						// 						document.getElementById("loginForm").Submit();
					} else if(xmltext == 0) {
						document.getElementById("checkFlag").innerHTML = "账户名密码不匹配！";

					}

				}
			}
		}
	}

	function tryRegiste() {

		var xmlReq = createXMLHttpRequest();

		var name = document.getElementById('registeForm').name.value;
		var account = document.getElementById('registeForm').account.value;
		var password = document.getElementById('registeForm').password.value;
		var firmPassword = document.getElementById('registeForm').firmPassword.value;

		if(!name) {
			document.getElementById("checkFlag2").innerHTML = "为自己起一个昵称吧！";
			return;
		} else if(!account) {
			document.getElementById("checkFlag2").innerHTML = "没有账号该怎样登陆呢！";
			return;
		} else if(!password) {
			document.getElementById("checkFlag2").innerHTML = "密码不能为空！";
			return;
		} else if(!firmPassword) {
			document.getElementById("checkFlag2").innerHTML = "确认密码不能为空！";
			return;
		} else if(password != firmPassword) {
			document.getElementById("checkFlag2").innerHTML = "确认密码与原密码不一致！请重新输入";
			document.getElementById('registeForm').password.value = null;
			document.getElementById('registeForm').firmPassword.value = null;
			return;
		};

		xmlReq.open("GET", "../Register?account=" + account + "&password=" + password + "&name=" + name + "&firmPassword=" + firmPassword, true);
		xmlReq.send(null);
		//	 console.log(xmlReq); 

		xmlReq.onreadystatechange = function() {
			if(xmlReq.readyState == 4) { //判断对象状态是否完成
				if(xmlReq.status == 200) { //信息已经成功返回
					var xmltext = xmlReq.responseText; //得到AjaxServlet往外输出的数据
					if(xmltext == 1) {
						alert("恭喜您注册成功!");
						document.getElementById('registeForm').name.value = "";
						document.getElementById('registeForm').account.value = "";
						document.getElementById('registeForm').password.value = "";
						document.getElementById('registeForm').firmPassword.value = "";
						// 						account=password=firmPassword = "";

						goLogin();
						document.getElementById("checkFlag").innerHTML = "";
						document.getElementById("checkFlag2").innerHTML = "";
					} else if(xmltext == 0) {
						document.getElementById("checkFlag2").innerHTML = "该账户已存在！";

					}

				}
			}
		}
	}

	//function tryLogin1() {
	//	document.getElementById("checkFlag").style.color = 'red';
	//	document.getElementById("checkFlag").innerHTML = "账户名密码不匹配！";
	//}

	//就绪状态处理器  
	//      xhr.onreadystatechange = function() {  
	//          if(this.readyState == 4) {          //忽略除DONE状态之外的所有状态  
	//              if (this.status >= 200 && this.status <300) {  
	//                  //成功  
	//                  var data = xhr.responseText;  
	//                  console.log(data);  
	//                  if(data=="fail"){   
	// 						document.getElementById("checkFlag").innerHTML="账户名密码不匹配！";
	//                  }else {  
	////                      var url = "Login"; 
	////                      location.href=url;//get发送  
	////                      post(url, {userId:data});   
	//                  }  
	//              }  
	//              else {  
	// 					document.getElementById("checkFlag").innerHTML="服务器端错误，请尝试重新登录";
	//              }  
	//          }  
	//      }; 
	//      
	//      var account=document.getElementById("loginForm").account.value;
	//      var account=document.getElementById("password").account.value;
	//      xhr.open("GET", "Login?account=" + account.value + "&password=" + password.value,true);  
	//      xhr.send(null);